package com.dao;

import com.beans.MenuInfo;
import com.jdbc.DBUtil;

import java.util.List;

public class MenuDao {

   public List<MenuInfo> getMenuList(int parentId){
       List<MenuInfo> menuList=DBUtil.getList("select * from menuInfo where parentId=?", MenuInfo.class, parentId);

       for(MenuInfo m: menuList) {
           if(m.getParentId()==0) {
               m.setSubMenuList( getMenuList( m.getId()));
           }
       }
       return menuList;
    }

    public List<MenuInfo> getMenuList(int parentId ,int roleId) {
        List<MenuInfo> menuList=DBUtil.getList("select * from menuInfo where parentId=? and id in (select menuId from rolemenu where roleId=? );", MenuInfo.class, parentId,roleId);
        for(MenuInfo m:menuList){
            if(m.getParentId()==0){
                m.setSubMenuList(getMenuList(m.getId(),roleId));
            }
        }
        return menuList;
    }
}
